package com.zjb.home.boxingtu.view.circle;

import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;

import com.zjb.home.boxingtu.R;
import com.zjb.home.boxingtu.view.BaseView;

public class QingChuangLiveDateView extends BaseView {

    private Paint paint;
    private float circleNei;
    private float circleWai;
    int du;
    public QingChuangLiveDateView(@NonNull Context context) {
        super(context);
    }

    public QingChuangLiveDateView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public QingChuangLiveDateView(@NonNull Context context, @Nullable AttributeSet attrs,
                                  int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void initAttrs(AttributeSet attrs) {

    }

    @Override
    public void init() {
        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setStyle(Paint.Style.STROKE);
        circleNei = getResources().getDimension(R.dimen.m3_5);
        circleWai = getResources().getDimension(R.dimen.m5);
    }

    {
        start();
    }

    @SuppressLint("DrawAllocation")
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        paint.setColor(Color.parseColor("#FFDBF2"));
        paint.setStrokeWidth(circleNei);
        canvas.drawCircle(getWidth() / 2f, getHeight() / 2f,
                getHeight() / 2f - circleWai - circleNei / 2f,
                paint);
        paint.setColor(Color.parseColor("#FF00B7"));
        paint.setStrokeWidth(circleWai);
        paint.setStrokeCap(Paint.Cap.ROUND);
        RectF oval1 = new RectF(getWidth() / 2f - getHeight() / 2f + circleWai / 2f, circleWai / 2f,
                getWidth() / 2f + getHeight() / 2f - circleWai / 2f, getHeight()-circleWai / 2f);
        canvas.drawArc(oval1, 180+30, du, false, paint);
    }

    public void setDu(int du) {
        this.du = du;
        invalidate();
    }

    public void start(){
        ObjectAnimator animator = ObjectAnimator.ofInt(this, "du",0, 270+15);
        animator.setDuration(1000);
        animator.setInterpolator(new FastOutSlowInInterpolator());
        animator.start();
    }


//    @Override
//    protected void onAttachedToWindow() {
//        super.onAttachedToWindow();
//        start();
//    }

}
